package com.dabay.web.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

/**
 * 辅助工具类
 * @author chenghj
 *
 */
public class Helper {
	//对象转换成string
    public String parseObjToStr(Object obj){
    	String resultStr = "";
    	if( null!= obj && ""!=obj && obj.toString().trim().length()>0 ){
    		resultStr = obj.toString().trim();
    	}
    	return resultStr;
    }  
  //long的string 转换为日期
    public String parseLongStrToDate(String longStr){
    	long num =0l;
    	String dateStr = "";
    	if(longStr.trim().length()>8){
    		num=Long.parseLong(longStr);
    		DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    		Calendar calendar = Calendar.getInstance();
    		calendar.setTimeInMillis(num);
    		dateStr = formatter.format(calendar.getTime());
    	}
    	return dateStr;
    } 
    public String encodeStr(String str) {  
    	/*str = parseObjToStr(str);
        try {  
            return new String(str.getBytes("ISO-8859-1"), "UTF-8");  
        } catch (UnsupportedEncodingException e) {  
            e.printStackTrace();  
            return "";  
        }  */
    	return str;
    } 
  //对象转换成string
    public int parseObjToInt(Object obj){
    	int resultInt = 0;
    	if( null!= obj && ""!=obj && obj.toString().trim().length()>0 ){
    		resultInt = Integer.parseInt(obj.toString().trim());
    	}
    	return resultInt;
    }  
    
    public String renshuInfo(Object man,Object women,Object no){
    	String resultStr =  "";
    	int manStr = parseObjToInt(man);
    	int womenStr = parseObjToInt(women);
    	int noStr = parseObjToInt(no);
    	if(manStr>0){
    		resultStr +=manStr+"人(男)";
    	}
    	if(womenStr>0){
    		resultStr +=womenStr+"人(女)";
    	}
    	if(noStr>0){
    		resultStr +=noStr+"人(不限)";
    	}
    	if(resultStr==""){
    		resultStr = "0人";
    	}
    	return resultStr;
    }
	/**
	 *生成随机数
	 */
    public static String getRandomString(int length){
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
          int number=random.nextInt(62);
          sb.append(str.charAt(number));
        }
        return sb.toString();
    }
    /**
	 *生成日期时间戳
	 */
    public static String getDateIntString(int length){
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
          int number=random.nextInt(62);
          sb.append(str.charAt(number));
        }
        return sb.toString();
    }

}




